import 'dart:convert';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:card_swiper/card_swiper.dart';
import 'package:common_utils/common_utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
import 'package:taonile/entity/product_detail_entity.dart';
import 'package:taonile/http/web_path.dart';
import 'package:taonile/routers/routers.dart';
import 'package:taonile/utils/singleton_manager.dart';
import 'package:webview_flutter/webview_flutter.dart';

import '../config/config.dart';
import '../http/api.dart';
import '../utils/common_utils.dart';
import '../utils/event_msg.dart';
import '../utils/user_utils.dart';
import '../views/number_controller_widget.dart';

class ProductDetailPage extends StatefulWidget {
  String productId = '';

  ProductDetailPage({Key? key, this.productId = ''}) : super(key: key);

  @override
  State<ProductDetailPage> createState() => _ProductDetailState();
}

class _ProductDetailState extends State<ProductDetailPage> {
  // late WebViewController controller;
  // double _webHeight = 750.w; //去计算得到网页的高度，然后设置高度
  // late double _originalHeight; //原高度

  var guigeSubIndex = [];
  var spuCurrent = '选择规格';
  var buyNum = '1';
  var bottomPopHeight = 440.w;

  ProductDetailEntity entity = ProductDetailEntity();
  ProductDetailDataSku currentSKu = ProductDetailDataSku();
  var imgs = [];

  //判断下一步是立即下单，还是加购
  var nextType = 1;

  // String html = """
  //  <!DOCTYPE html>
  //       <html>
  //       <head><meta name="viewport" content="width=device-width, initial-scale=1.0"></head>
  //         <body>
  //           <p> Hello WebView 掘金</p>
  //           <img src="/obj/static/xitu_juejin_web/e08da34488b114bd4c665ba2fa520a31.svg"/>
  //         </body>
  //       </html>
  //       <script>
  //         const resizeObserver = new ResizeObserver(entries =>
  //         Resize.postMessage(document.documentElement.scrollHeight.toString()) )
  //         resizeObserver.observe(document.body)
  //       </script>
  // """;

  @override
  void initState() {
    super.initState();
    // controller = WebViewController();
    // controller.setJavaScriptMode(JavaScriptMode.unrestricted);
    // controller.setBackgroundColor(const Color(0x00000000));
    // controller.loadHtmlString(html, baseUrl: "https://lf3-cdn-tos.bytescm.com");
    // controller.addJavaScriptChannel('Resize', onMessageReceived: (JavaScriptMessage message) {
    //   double height = double.parse(message.message);
    //   setState(() {
    //     if (_webHeight == 0) {
    //       _webHeight = height;
    //     }
    //   });
    // });

    getProductDetal();
    // controller.setNavigationDelegate(
    //   NavigationDelegate(onPageFinished: (url) async {
    //     //获取webView原始高度
    //     var originalHeight =
    //         await controller.runJavaScriptReturningResult("document.body.offsetHeight;");
    //     print('网页高度1-----$originalHeight');
    //     _originalHeight = double.parse(originalHeight.toString());
    //     setState(() {
    //       _webHeight = _originalHeight / 2.8;
    //       if (_webHeight > 3500) {
    //         _webHeight = 3500;
    //       }
    //     });
    //     print('网页高度2-----$_originalHeight');
    //   }),
    // );
    // LogUtil.v('${Config.webUrl}${WebPath.productDetail}${widget.productId}');
    // controller
    //     .loadRequest(Uri.parse('${Config.webUrl}${WebPath.productDetail}${widget.productId}'));
  }

  getProductDetal() async {
    dynamic result = await Api.goodsDetail("/${widget.productId}");
    setState(() {
      entity = ProductDetailEntity.fromJson(result);
      guigeSubIndex.clear();
      for (var element in entity.data.spec) {
        guigeSubIndex.add(0);
      }
      getSpecStr();
      imgs = entity.data.img;
    });
  }

  addCard() async {
    dynamic result = await Api.addShoppingCar({
      'store_id': entity.data.storeId,
      'goods_id': entity.data.id,
      'sku_id': currentSKu.id,
      'num': buyNum,
    });
    var jsonResult = jsonDecode(jsonEncode(result));
    if (jsonResult['code'] == 1) {
      EasyLoading.showToast("添加购物车成功");
      SingletonManager.instance.eventBus.fire(ShoppingCarUp());
    }
  }

  getSpecStr() {
    StringBuffer sb = StringBuffer();
    for (int i = 0; i < guigeSubIndex.length; i++) {
      sb.write(entity.data.spec[i].items[guigeSubIndex[i]]);
      if (i != guigeSubIndex.length - 1) {
        sb.write('/');
      }
    }
    spuCurrent = sb.toString();
    print('当前的SPU=$spuCurrent');
    getSkuObj();
  }

  getSkuObj() {
    for (int i = 0; i < entity.data.sku.length; i++) {
      List<String> skuList = entity.data.sku[i].specVal;
      StringBuffer sb = StringBuffer();
      for (int j = 0; j < skuList.length; j++) {
        // print('第${i+1}组 spec');
        sb.write(skuList[j]);
        if (j != skuList.length - 1) {
          sb.write('/');
        }
      }
      // print(sb.toString());
      if (spuCurrent == sb.toString()) {
        // print("選中的SKU是第$i個");
        // print('值=$spuCurrent');
        currentSKu = entity.data.sku[i];
        break;
      }
    }
  }

  collection() async {
    dynamic result = await Api.collection({'id': widget.productId, 'type': 'goods'});
    setState(() {
      var jsonResult = jsonDecode(jsonEncode(result));
      if (jsonResult['code'] == 1) {
        EasyLoading.showToast(jsonResult['msg']);

        getProductDetal();
      }
    });
  }

  Widget getGuigeTitleItem(int index, Function func) {
    return Container(
      width: double.infinity,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            height: 70.w,
            decoration: BoxDecoration(color: Colors.transparent),
            alignment: Alignment.centerLeft,
            child: Text(
              entity.data.spec[index].name,
              style: TextStyle(fontSize: 24.sp, color: Config.colorText1),
            ),
          ),
          Container(
            margin: EdgeInsets.symmetric(vertical: 0.w),
            height: 50.w,
            width: double.infinity,
            child: GridView.builder(
              shrinkWrap: true,
              physics: const NeverScrollableScrollPhysics(),
              itemCount: entity.data.spec[index].items.length,
              padding: EdgeInsets.symmetric(vertical: 0.w, horizontal: 0.w),
              itemBuilder: (BuildContext context, int index2) {
                return getGuigeSubItem(index, index2, () {
                  func(index, index2);
                  // guigeSubIndex[index] = index2;
                  setState(() {
                    getSpecStr();
                  });
                });
              },
              gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                  crossAxisCount: 4,
                  mainAxisSpacing: 15.w,
                  crossAxisSpacing: 30.w,
                  childAspectRatio: 3.5),
            ),
          ),
        ],
      ),
    );
  }

  Widget getGuigeSubItem(int index, int index2, Function()? func) {
    return StatefulBuilder(builder: (context1, state) {
      return InkWell(
        onTap: func,
        child: Container(
          width: 60.w,
          alignment: Alignment.center,
          // height: 55.w,
          decoration: index2 == guigeSubIndex[index]
              ? BoxDecoration(
                  color: Config.colorMain,
                  borderRadius: BorderRadius.circular(20.w),
                )
              : BoxDecoration(
                  border: Border.all(color: Config.colorText3, width: 2.w),
                  borderRadius: BorderRadius.circular(20.w),
                ),
          padding: EdgeInsets.symmetric(vertical: 3.w, horizontal: 10.w),
          child: Text(entity.data.spec[index].items[index2],
              style: TextStyle(
                  fontSize: 16.sp,
                  color: index2 == guigeSubIndex[index] ? Config.colorWhite : Config.colorText1)),
        ),
      );
    });
  }

  _showBasicModalBottomSheet(context, bool isBuy) async {
    return showModalBottomSheet(
      isScrollControlled: false,
      context: context,
      backgroundColor: Colors.transparent,
      builder: (BuildContext context) {
        return StatefulBuilder(builder: (context1, state) {
          return Container(
            width: double.infinity,
            height: bottomPopHeight + (guigeSubIndex.length * 121.w),
            // + (guigeSubIndex.length * 120.w)
            padding: EdgeInsets.symmetric(vertical: 0.w, horizontal: 5.w),
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.only(
                topLeft: Radius.circular(15.w),
                topRight: Radius.circular(15.w),
              ),
            ),
            child: Column(
              children: [
                //规格图片价格等
                Container(
                  height: 200.w,
                  margin: EdgeInsets.symmetric(horizontal: 5.w, vertical: 0.w),
                  decoration: BoxDecoration(
                    border: Border(
                      bottom: BorderSide(color: Config.colorDivider, width: 2.w),
                    ),
                  ),
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Container(
                        margin: EdgeInsets.only(left: 20.w, right: 20.w),
                        child: ClipRRect(
                          borderRadius: BorderRadius.circular(5),
                          child: CachedNetworkImage(
                            imageUrl: currentSKu.id.isNotEmpty ? currentSKu.imgPath : '',
                            fit: BoxFit.fill,
                            width: 140.w,
                            height: 140.w,
                            errorWidget: (context, url, error) {
                              return Image.asset(
                                'assets/images/bg_default_400.png',
                                width: 140.w,
                                height: 140.w,
                                fit: BoxFit.fill,
                              );
                            },
                          ),
                        ),
                      ),
                      Container(
                        height: 140.w,
                        width: 480.w,
                        child: Stack(
                          children: [
                            Text(
                              currentSKu.id.isNotEmpty
                                  ? CommonUtils.formatAmountUnit(currentSKu.money,
                                      currentSKu.company, currentSKu.money1, currentSKu.company1)
                                  : '',
                              softWrap: true,
                              maxLines: 2,
                              overflow: TextOverflow.ellipsis,
                              style: TextStyle(color: Colors.red, fontSize: 26.w),
                            ),
                            Positioned(
                              bottom: 32.w,
                              child: Text(
                                "库存 ${currentSKu.id.isNotEmpty ? currentSKu.stock : ''}",
                                style: TextStyle(fontSize: 22.sp, color: Config.colorText1),
                              ),
                            ),
                            Positioned(
                              bottom: 0.w,
                              child: Text(
                                "规格 $spuCurrent",
                                style: TextStyle(fontSize: 22.sp, color: Config.colorText1),
                              ),
                            ),
                          ],
                        ),
                      ),
                    ],
                  ),
                ),
                //规格的选择
                Container(
                  // height: 0,
                  decoration: BoxDecoration(
                    border: Border(
                      bottom: BorderSide(color: Config.colorDivider, width: 2.w),
                    ),
                  ),
                  padding: EdgeInsets.symmetric(horizontal: 25.w, vertical: 0.w),
                  child: ListView.builder(
                    shrinkWrap: true,
                    physics: const NeverScrollableScrollPhysics(),
                    itemCount: entity.data.spec.length,
                    itemBuilder: (BuildContext context, int index) {
                      return getGuigeTitleItem(index, (index, index2) {
                        state(() {
                          guigeSubIndex[index] = index2;
                          getSpecStr();
                        });
                      });
                    },
                  ),
                ),
                //购买数量
                Container(
                  width: double.infinity,
                  decoration: BoxDecoration(
                    border: Border(
                      bottom: BorderSide(color: Config.colorDivider, width: 2.w),
                    ),
                  ),
                  padding: EdgeInsets.symmetric(horizontal: 25.w),
                  height: 100.w,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        "购买数量",
                        style: TextStyle(fontSize: 28.sp, color: Config.colorText1),
                      ),
                      NumberControllerWidget(
                        numText: buyNum,
                        addValueChanged: (num) {
                          setState(() {
                            buyNum = num.toString();
                          });
                        },
                        removeValueChanged: (num) {
                          setState(() {
                            buyNum = num.toString();
                          });
                        },
                        updateValueChanged: (num) {},
                      )
                    ],
                  ),
                ),
                Container(
                  padding: EdgeInsets.symmetric(vertical: 15.w),
                  width: 690.w,
                  height: 120.w,
                  child: ElevatedButton(
                    clipBehavior: Clip.antiAlias,
                    onPressed: () async {
                      Navigator.pop(context);
                      if (isBuy) {
                        if (await UserUtils.isLogin() == false) {
                          EasyLoading.showToast('请先登录');
                          Routes.navigateTo(context, Routes.login);
                          return;
                        }
                        //如果是加购，就不用跳转
                        if (nextType == 2) {
                          addCard();
                        } else {
                          //直接下单，跳转去确认
                          SingletonManager.instance.currentSKu = currentSKu;

                          Routes.navigateTo(context, Routes.orderConfirm, params: {
                            'buyNum': buyNum,
                            'tag': entity.data.tag,
                            'productName': entity.data.name,
                            'storeName': entity.data.store.name,
                            'storeId': entity.data.storeId,
                            'storeLogo': entity.data.store.logo,
                            'expressMoney': entity.data.storeExpressMoney.isNotEmpty
                                ? entity.data.storeExpressMoney
                                : '0',
                            'isCar': '0'
                          });
                        }
                      }
                    },
                    style: ElevatedButton.styleFrom(shape: const StadiumBorder()),
                    child: const Text('确定'),
                  ),
                ),
              ],
            ),
          );
        });
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar: Container(
        decoration: const BoxDecoration(color: Config.colorBg),
        height: 100.w,
        width: 750.w,
        alignment: Alignment.center,
        padding: EdgeInsets.only(left: 20.w, right: 5.w),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            SizedBox(
              width: 80.w,
              child: InkWell(
                onTap: () {
                  if (entity.code == 0) {
                    return;
                  }
                  Routes.navigateTo(context, Routes.mallHome,
                      params: {'storeId': entity.data.storeId});
                },
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Image.asset(
                      'assets/images/icon_product_store.png',
                      width: 40.w,
                      height: 40.w,
                    ),
                    Text('店铺',
                        style: TextStyle(fontSize: 21.sp, height: 1.5, color: Config.colorText1)),
                  ],
                ),
              ),
            ),
            SizedBox(
              width: 80.w,
              child: InkWell(
                onTap: () {
                  // setState(() {
                  //   isCollect = !isCollect;
                  // });
                  collection();
                },
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Image.asset(
                      (entity.code == 1 && entity.data.isSave == '1')
                          ? 'assets/images/icon_product_collect_p.png'
                          : 'assets/images/icon_product_collect_n.png',
                      width: 40.w,
                      height: 40.w,
                    ),
                    Text('收藏',
                        style: TextStyle(fontSize: 21.sp, height: 1.5, color: Config.colorText1)),
                  ],
                ),
              ),
            ),
            SizedBox(
              width: 550.w,
              child: Row(
                children: [
                  Visibility(
                    visible: entity.code == 1 && entity.data.tag != '1',
                    child: Expanded(
                      child: Container(
                        margin: EdgeInsets.only(left: 9.w, right: 9.w),
                        child: ElevatedButton(
                          clipBehavior: Clip.antiAlias,
                          onPressed: () async {
                            nextType = 2;
                            _showBasicModalBottomSheet(context, true);
                          },
                          style: ElevatedButton.styleFrom(
                              primary: Colors.orange, shape: const StadiumBorder()),
                          child: Text(
                            '加入购物车',
                            style: TextStyle(color: Config.colorWhite, fontSize: 26.sp),
                          ),
                        ),
                      ),
                    ),
                  ),
                  Expanded(
                    child: Container(
                      margin: EdgeInsets.only(left: 9.w, right: 9.w),
                      child: ElevatedButton(
                        clipBehavior: Clip.antiAlias,
                        onPressed: () async {
                          nextType = 1;
                          _showBasicModalBottomSheet(context, true);
                        },
                        style: ElevatedButton.styleFrom(shape: const StadiumBorder()),
                        child: Text(
                          '立即购买',
                          style: TextStyle(color: Config.colorWhite, fontSize: 26.sp),
                        ),
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
      body: Container(
        width: double.infinity,
        color: Config.colorBg2,
        height: double.infinity,
        child: Stack(children: [
          //中部内容部分
          SingleChildScrollView(
            scrollDirection: Axis.vertical,
            child: Column(
              children: [
                SizedBox(
                  //轮播
                  height: 745.w,
                  child: Swiper(
                    itemBuilder: (BuildContext context, int index) {
                      return CachedNetworkImage(
                        imageUrl: CommonUtils.compressImageUrl(imgs[index], 750, 750),
                        fit: BoxFit.fill,
                        width: 750.w,
                        height: 745.w,
                        errorWidget: (context, url, error) {
                          return Image.asset(
                            'assets/images/bg_default_400.png',
                            width: 750.w,
                            height: 745.w,
                            fit: BoxFit.fill,
                          );
                        },
                      );
                    },
                    onTap: (index) {},
                    loop: false,
                    autoplay: false,
                    layout: SwiperLayout.DEFAULT,
                    // itemCount: entity.data.img.length,
                    itemCount: imgs.length,
                    // viewportFraction: 0.7,
                    // scale: 0.8,
                    pagination: SwiperPagination(
                      builder: DotSwiperPaginationBuilder(
                          // size: Size(20.w, 4.w),
                          // activeSize: Size(20.w, 4.w),
                          size: 15.w,
                          activeSize: 15.w,
                          activeColor: Config.colorMain,
                          color: Config.colorWhite),
                    ),
                  ),
                ),
                //商品标题价格部分
                Container(
                  padding: EdgeInsets.symmetric(horizontal: 25.w, vertical: 20.w),
                  decoration: BoxDecoration(color: Config.colorBg),
                  width: double.infinity,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Padding(padding: EdgeInsets.only(top: 0.w)),
                      Text(
                        entity.data.name,
                        style: TextStyle(color: Config.colorText1, fontSize: 28.sp),
                      ),
                      Padding(padding: EdgeInsets.only(top: 10.w)),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            //entity.data.sku[0].price
                            entity.code == 1
                                ? CommonUtils.formatAmountUnit(entity.data.money,
                                    entity.data.company, entity.data.money1, entity.data.company1)
                                : '',
                            style: TextStyle(color: Colors.redAccent, fontSize: 26.sp),
                          ),
                          Text(
                            '已售${(entity.code == 1 ? entity.data.salesNum : '0')}',
                            style: TextStyle(color: Config.colorText3, fontSize: 24.sp),
                          ),
                        ],
                      ),
                      Padding(padding: EdgeInsets.only(top: 4.w)),
                    ],
                  ),
                ),
                InkWell(
                  onTap: () {
                    _showBasicModalBottomSheet(context, false);
                  },
                  child: Container(
                      width: double.infinity,
                      padding: EdgeInsets.symmetric(horizontal: 25.w, vertical: 25.w),
                      margin: EdgeInsets.only(top: 2.w),
                      decoration: BoxDecoration(color: Config.colorBg),
                      child: Row(
                        children: [
                          Expanded(
                            flex: 3,
                            child: Text(
                              '规格',
                              style: TextStyle(color: Config.colorText3, fontSize: 24.sp),
                            ),
                          ),
                          Expanded(
                            flex: 12,
                            child: Text(
                              spuCurrent,
                              style: TextStyle(color: Config.colorText1, fontSize: 24.sp),
                            ),
                          ),
                          Expanded(
                            flex: 3,
                            child: Container(
                              alignment: Alignment.centerRight,
                              child: Icon(
                                Icons.arrow_forward_ios,
                                size: 25.w,
                              ),
                            ),
                          ),
                        ],
                      )),
                ),
                Container(
                  width: double.infinity,
                  margin: EdgeInsets.only(top: 20.w),
                  padding: EdgeInsets.symmetric(horizontal: 25.w, vertical: 25.w),
                  decoration: BoxDecoration(color: Config.colorBg),
                  child: Column(
                    children: [
                      Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Container(
                            margin: EdgeInsets.only(right: 20.w),
                            child: ClipRRect(
                              borderRadius: BorderRadius.circular(5),
                              child: CachedNetworkImage(
                                imageUrl: entity.code == 1 ? entity.data.store.logo : '',
                                fit: BoxFit.fill,
                                width: 100.w,
                                height: 100.w,
                                errorWidget: (context, url, error) {
                                  return Image.asset(
                                    'assets/images/bg_default_400.png',
                                    width: 100.w,
                                    height: 100.w,
                                    fit: BoxFit.fill,
                                  );
                                },
                              ),
                            ),
                          ),
                          Text(
                            entity.code == 1 ? entity.data.store.name : '',
                            softWrap: true,
                            maxLines: 2,
                            overflow: TextOverflow.ellipsis,
                            style: TextStyle(color: (Config.colorText1), fontSize: 28.w),
                          ),
                        ],
                      ),
                      Padding(
                        padding: EdgeInsets.all(10.w),
                      ),
                      Container(
                        margin: EdgeInsets.symmetric(horizontal: 30.w),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceAround,
                          children: [
                            InkWell(
                              onTap: () {
                                Routes.navigateTo(context, Routes.mallHome,
                                    params: {'storeId': entity.data.storeId});
                              },
                              child: Text(
                                '进店逛逛',
                                style: TextStyle(color: (Config.colorText1), fontSize: 28.w),
                              ),
                            ),
                            SizedBox(
                              height: 30.w,
                              child: VerticalDivider(
                                width: 2.w,
                                color: Config.colorText3,
                                thickness: 2.w,
                              ),
                            ),
                            InkWell(
                              onTap: () {
                                Routes.navigateTo(context, Routes.mallHome,
                                    params: {'storeId': entity.data.storeId, 'currentIndex': "1"});
                              },
                              child: Text(
                                '全部商品',
                                style: TextStyle(color: (Config.colorText1), fontSize: 28.w),
                              ),
                            ),
                          ],
                        ),
                      ),
                    ],
                  ),
                ),
                //商品详情
                Container(
                  width: double.infinity,
                  margin: EdgeInsets.only(top: 20.w),
                  padding: EdgeInsets.only(top: 25.w, bottom: 1.w),
                  decoration: BoxDecoration(color: Config.colorBg),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Container(
                            width: 140.w,
                            height: 60.w,
                            margin: EdgeInsets.only(right: 20.w),
                            child: Divider(
                              color: Config.colorText3,
                              height: 50.w,
                              thickness: 2.w,
                            ),
                          ),
                          Text(
                            '商品详情',
                            style: TextStyle(color: Config.colorText1, fontSize: 28.sp),
                          ),
                          Container(
                            width: 140.w,
                            height: 60.w,
                            margin: EdgeInsets.only(left: 20.w),
                            child: Divider(
                              color: Config.colorText3,
                              height: 50.w,
                              thickness: 2.w,
                            ),
                          ),
                        ],
                      ),
                      Padding(
                        padding: EdgeInsets.only(top: 25.w),
                      ),
                      Container(
                        width: 750.w,
                        // height: _webHeight,
                        // height: 750.w,
                        child:

                            // WebViewWidget(
                            //   controller: controller,
                            // ),
                            HtmlWidget(
                          entity.data.detail,
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
          Container(
            //顶部标题栏
            decoration: const BoxDecoration(color: Colors.transparent),
            height: 100.w,
            alignment: Alignment.centerLeft,
            margin: EdgeInsets.only(top: 60.w),
            padding: EdgeInsets.symmetric(horizontal: 30.w),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                InkWell(
                  onTap: () {
                    Routes.router.pop(context);
                  },
                  child: Container(
                    padding: EdgeInsets.only(left: 18.w),
                    decoration: BoxDecoration(
                      color: Config.colorBg,
                      borderRadius: BorderRadius.circular(35.w),
                    ),
                    width: 70.w,
                    height: 70.w,
                    child: Icon(
                      Icons.arrow_back_ios,
                      size: 45.w,
                    ),
                  ),
                ),
                Visibility(
                  visible: entity.code == 1 && entity.data.tag != '1',
                  child: InkWell(
                    onTap: () {
                      Routes.navigateTo(context, Routes.shoppingCar);
                    },
                    child: Container(
                      padding: EdgeInsets.only(left: 10.w),
                      decoration: BoxDecoration(
                        color: Config.colorBg,
                        borderRadius: BorderRadius.circular(35.w),
                      ),
                      width: 70.w,
                      height: 70.w,
                      child: Icon(
                        Icons.shopping_cart_outlined,
                        size: 45.w,
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ),
        ]),
      ),
    );
  }
}
